package com.dolphin.common.component.var.model;

import com.dolphin.common.component.var.enums.VarTypeEnum;
import com.dolphin.common.utils.JsonInterface;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * @author shida
 */
@Getter
@Setter
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class GlobalRefVarModel extends VarModel{
    private GlobalRefVarDefinition globalRefVarDefinition;
    private BaseVarModel calculateModel;

    public GlobalRefVarDefinition getGlobalVarDefinition(){
        if(globalRefVarDefinition == null){
            globalRefVarDefinition = JsonInterface.json2Object(super.getDefinition(), GlobalRefVarDefinition.class);
        }
        return globalRefVarDefinition;
    }

    public VarTypeEnum getCalculateType(){
        return  getSubType().equals(VarTypeEnum.EXT_FUNCTION_VAR.getCode())
                ? VarTypeEnum.EXT_FUNCTION_VAR : VarTypeEnum.EXT_SCRIPT_VAR;
    }
}
